<template>
	<view class="note">
		<view class="note-title u-flex">
			<view v-if="info.BizType == 21">{{$t('chat.request_friend')}}</view>
			<view v-else-if="info.BizType == 22">{{$t('chat.request_friend_notify')}}</view>
			<view v-else>{{info.Title}}</view>
			<u-tag class="mgl-10" v-if="info.DealType == 2" :text="$t('chat.stat_ignored')" mode="plain" type="info"
				size="mini" />
			<u-tag class="mgl-10" v-if="info.DealType == 1" :text="$t('chat.stat_agreed')" mode="plain"
				size="mini" />
		</view>
		<view class="note-time">{{info.AddTimeText}}</view>
		<view class="note-txt">
			<text v-if="info.BizType == 21">{{$t('chat.user_iam')}} </text>
			{{info.Content}}
			<text v-if="info.Title == $t('chat.request_friend_notify') && info.DealType == 2"> {{$t('chat.stat_ignored')}}</text>
			<text v-if="info.Title == $t('chat.request_friend_notify') && info.DealType == 1"> {{$t('chat.stat_agreed')}}</text>
		</view>
		<view v-if="info.BizType == 21 && info.DealTime == 0" class="note-btns">
			<u-button @click="actRefuse">{{$t('chat.btn_ignore')}}</u-button>
			<u-button type="primary" @click="actAgree">{{$t('chat.btn_agree')}}</u-button>
		</view>
		<view v-if="info.Type == 1" class="note-btns">
			<u-button v-if="info.ExtDataJson.topic != undefined" type="primary" @click="goTopic()">{{$t('chat.btn_go_topic')}}
			</u-button>
			<u-button
				v-if="vuex_user.type == 1 && info.ExtDataJson.Pid != undefined && info.Title !='工程变动确认结果通知' && info.Title !='Workscope Contents Confirmation Result Notice.' && info.Title !='Уведомление о результате подтверждения содержания работ.'"
				type="primary" @click="$goPage('/staff/bench/detail',{project:info.ExtDataJson.Pid,tab:4})">
				{{$t('chat.btn_go_confirm')}}
			</u-button>
			<u-button
				v-if="vuex_user.type == 2 && info.ExtDataJson.Pid != undefined && info.Title !='工程变动确认结果通知' && info.Title !='Workscope Contents Confirmation Result Notice.' && info.Title !='Уведомление о результате подтверждения содержания работ.'"
				type="primary" @click="$goPage('/client/repair/detail',{project:info.ExtDataJson.Pid,tab:3})">
				{{$t('chat.btn_go_confirm')}}
			</u-button>
			<u-button v-if="info.ExtDataJson.demand != undefined" type="primary" @click="goDemand()">
				{{$t('chat.btn_go_check')}}
			</u-button>
		</view>
		<view class="detail-repair_content" v-if="list && JSON.parse(JSON.stringify(list)).length > 0">
			<view class="detail-repair_item" v-for="(item, index) in list">
				<view v-if="vuex_user.type == 2 && item.Stat==3 " class="note-index"
					@click="$goPage('/repair/edit',{title:'编辑',project:item.Pid,iid:item.Iid,stat:6})">
					<u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
					<text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
				</view>
				<view v-else-if="vuex_user.type == 1 && item.Stat==3 " class="note-index"
					@click="$goPage('/repair/edit',{title:'编辑',project:item.Pid,iid:item.Iid,stat:5})">
					<u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
					<text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
				</view>
				<view v-else class="note-index">
					<u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
					<text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
				</view>
				<view class="note-txt u-flex mgb-10">
					<text class="detail-repair_item--child__value  u-flex-1">{{item.ItemName}}</text>
				</view>
				<view class="note-txt">
					<template v-for="(updates,index) in item.UpdateList">
						<view class="mgb-10">{{updates}}<br /></view>
					</template>
				</view>
				<!-- <view class="u-flex mgb-10">
					<view class="detail-repair_item--child__label">{{i18n.submit_data}}：</view>
					<text
						class="detail-repair_item--child__value  u-flex-1">{{item.AddTimeText != '' ? item.AddTimeText : '-'}}</text>
				</view>
				<view class="u-flex mgb-10">
					<view class="detail-repair_item--child__label">{{i18n.submit_person}} ：</view>
					<text
						class="detail-repair_item--child__value  u-flex-1">{{ item.AddAccName != '' ? item.AddAccName : '-'}}</text>
				</view>
				<view class="u-flex">
					<view class="detail-repair_item--child__label">{{i18n.status}}：</view>
					<view class="detail-repair_item--child__value  u-flex-1">
						{{ item.StatText == '' ? '-' : i18n.materials_stat[item.Stat]}}
						<text v-if="item.Stat == 2 && item.DoneTimeText != ''" class="color-gray">
							({{item.DoneTimeText}})</text>
					</view>
				</view>
				<view class="u-flex mgt-10" v-if="item.Type != ''">
					<view class="detail-repair_item--child__label">{{i18n.spare_type}}：</view>
					<text class="detail-repair_item--child__value  u-flex-1">{{item.Type}}</text>
				</view>
				<view class="u-flex mgt-10" v-if="item.TypeText != ''">
					<view class="detail-repair_item--child__label">{{i18n.spare_name}}：</view>
					<text
						class="detail-repair_item--child__value  u-flex-1">{{item.TypeText}}</text>
				</view>-->
			</view>
			<!-- <u-loadmore :status="status" :icon-type="iconType" :load-text="loadText"
				margin-bottom="45" margin-top="45" color="#C1C0C0" /> -->
		</view>
	</view>
</template>

<script>
	import i18n from '@/lang/index'
	import pageMixin from '@/utils/pageMixin';
	export default {
		mixins: [pageMixin],
		data() {
			return {
				info: {},
				sid: '',
				list: {},
			}
		},

		onLoad(opts) {
			this.sid = opts.sid;
			this.getinfo()
		},
		computed: {
			i18n() {
				return this.$t('chat')
			},
			i18np() {
				return this.$t('project')
			}
		},
		methods: {
			getinfo() {
				let that = this;
				that.$http.get('/msg/system/info', {
					sid: that.sid
				}).then(res => {
					that.list = res.list
					let bizType = res.info.BizType;
					let content = res.info.Content;
					if (that.$t('chat.msg_title_'+ bizType)!== undefined) {
						res.info.Title = that.$t('chat.msg_title_'+ bizType);
					}
					if (that.$t('chat.msg_content_'+ bizType) !== undefined) {
						//let number = res.Content.replace(/[^0-9]/ig, "");
						let number = (res.info.Content.match(/\d+个工程/g) + "").match(/\d+/g);
						content = that.$t('chat.msg_content_'+ bizType);
						if (i18n.global.locale == '中文') {
							content = content.replace('[projectName]', res.info.ProjectName)
						} else {
							content = content.replace('[projectName]', res.info.ShipName)
						}
						content = content.replace('[userName]', res.info.ExtDataJson.AddAccName || '')
						content = content.replace('[groupName]', "【" +res.info.ExtDataJson.group_name+ "】" || '')
						content = content.replace('[number]', number)
						res.info.Content = content;
					}

					//确认结果状态，2：确认、3：驳回
					let stat = res.info.ExtDataJson.Stat || 0;
					if (stat == 3) {
						let rejectRmk = res.info.ExtDataJson.RejectRmk || '';
						if (rejectRmk != '') {
							content = content.replace('[rejectRmk]', rejectRmk)
							res.info.Content = content;
						}
					} else if (stat == 2) {
						if (that.$t('chat.msg_content_' + bizType + '_confirm')!== undefined) {
							//let number = res.info.Content.replace(/[^0-9]/ig, "");
							let number = (res.info.Content.match(/\d+个工程/g) + "").match(/\d+/g);
							let content = that.$t('chat.msg_content_' + bizType + '_confirm');
							if (i18n.global.locale == '中文') {
								content = content.replace('[projectName]', res.info.ProjectName)
							} else {
								content = content.replace('[projectName]', res.info.ShipName)
							}
							content = content.replace('[userName]', res.info.ExtDataJson.AddAccName || '')
							content = content.replace('[number]', number)
							res.info.Content = content;
						}
					}
					that.info = res.info;

					if (that.list) {
						var UpdateList = [];
						for (var item of that.list) {
							if (item.StatText == '待确认') {
								item.StatText = this.$t('project.no_confirmed')
							}
							if (item.StatText == '已确认') {
								item.StatText = this.$t('project.confirmed')
							}
							if (item.StatText == '驳回') {
								item.StatText = this.$t('project.reject')
							}
							if (item.UpdateList) {
								item.UpdateList.forEach(item1 => {
									item1 = item1.replace("编辑工程内容", this.$t('project.edit_project_content'));
									item1 = item1.replace('编辑单位', this.$t('project.edit_unit'));
									item1 = item1.replace('编辑数量', this.$t('project.edit_number'));
									item1 = item1.replace('编辑备注', this.$t('project.edit_remark'));
									item1 = item1.replace('编辑单价', this.$t('project.edit_unit_price'));
									item1 = item1.replace('新增工程内容', this.$t('project.add_project_content'));
									item1 = item1.replace('新增', this.$t('project.btn_add'));
									item1 = item1.replace('删除工程内容', this.$t('project.del_project_content'));
									item1 = item1.replace('删除', this.$t('project.btn_del'));
									item1 = item1.replace('撤回删除工程内容', this.$t('project.recall_del_project_content'));
									item1 = item1.replace('撤回删除', this.$t('project.recall_del'));
									UpdateList.push(item1)
								})
								item.UpdateList = UpdateList;
								UpdateList = []
							}
						}
					}
				})
			},
			goTopic() {
				var tid = this.info.ExtDataJson.topic;
				//判断帖子是否已删除
				this.$http.get('/bbs/topic/isdel', {
					tid: tid
				}).then(res => {
					if (res == 1) {
						this.$u.route('/pages/article/detail/index', {
							tid: tid
						});
					}
				})
			},
			goDemand() {
				this.$u.route('/pages/demand/detail/index', {
					dkey: this.info.ExtDataJson.demand
				});
			},
			actAgree() {
				let data = {
					sid: this.sid,
					deal_type: 1,
				};
				this.$http.post('/msg/system/deal', data).then(res => {
					uni.showToast({
						title: '同意成功'
					});
					this.getinfo();
				});
			},
			actRefuse() {
				let data = {
					sid: this.sid,
					deal_type: 2,
				};
				this.$http.post('/msg/system/deal', data).then(res => {
					uni.showToast({
						title: '忽略成功'
					});
					this.getinfo();
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mgl-10 {
		margin-left: 10rpx;
	}

	.note {
		white-space: normal;
		word-break: break-all;
		padding: 60rpx 30rpx;

		&-title {
			font-size: 30rpx;
			color: #131313;
			margin-bottom: 30rpx;
		}

		&-time {
			font-size: 24rpx;
			color: #999999;
			margin-bottom: 40rpx;
		}

		&-txt {
			text-indent: 44rpx;
			font-size: 28rpx;
			color: #666666;
			line-height: 44rpx;
		}

		&-index {
			margin-left: 32rpx;
		}

		&-btns {
			position: fixed;
			width: 100%;
			bottom: 0;
			left: 0;
			text-align: center;

			.u-btn {
				display: inline-block;
				margin: 30rpx;
			}
		}
	}
</style>
